<?php

namespace App\Http\Controllers\Admin;

use App\Models\City;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CityController extends Controller
{
    public function index()
    {
        return view('admin.city.index');
    }
    public function data(Request $request)
    {
        $model = City::query();
        if ($request->get('name')){
            $model = $model->where('name','like','%'.$request->get('name').'%');
        }
        $res = $model->orderBy('id','asc')->paginate($request->get('limit',30))->toArray();
        $data = [
            'code' => 0,
            'msg'   => 'ok...',
            'count' => $res['total'],
            'data'  => $res['data']
        ];
        return response()->json($data);
    }

}
